<?php
defined( '_JEXEC' ) or die( 'Restricted Access' );
/**
 * @version     $Id$
 * @package     Virtuemart
 * @subpackage  SemanticWeb Module
 * @copyright   Copyright (C) 2009 Alex Stolz - All rights reserved.
 * @license     GNU/GPL v2
 * SemanticWeb is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2
 * as published by the Free Software Foundation.
 
 * SemanticWeb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 
 * You should have received a copy of the GNU General Public License
 * along with SemanticWeb; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

global $vmLogger;
$configuration_done = 0;
// check if request-option is com_virtuemart
if(!empty($option) && $option=='com_virtuemart'):
	require_once(dirname(__FILE__).DS.'helper.php');
	$configuration_done = $params->get('configuration_done');
	$option = JRequest::getVar('option');
	// create an instance of the controller
	$controller = new ModSemanticWebController;
	// check if the Virtuemart component is enabled
	if($controller->isVirtueMartEnabled()):
		// set params also for the controller class
		$controller->setParams($params);
		// set a custom OWL filename
		$filename = "";
		$owlfilename = $params->get('owl_filename');
		if(eregi('^[a-z0-9_\-]+\.[a-z]+$', $owlfilename))
			$filename = $owlfilename;
		$controller->setFilename($filename);
		// set a custom special validity duration
		$special_validity = $params->get('special_validity');
		$controller->setSpecialValidity($special_validity);
		// set a custom offering validity duration
		$offering_validity = $params->get('offering_validity');
		$controller->setOfferingValidity($offering_validity);
		// set a timeout for the files (a longer time span speeds the application up)
		$timeout = $params->get('timeout');
		$controller->setTimeout($timeout);
		// check, if configuration needs to be done
		if(!file_exists(dirname(__FILE__).DS.'mod_semanticweb.xml') || empty($configuration_done)) {
			require_once(dirname(__FILE__).DS.'create_manifest.php');
			$vmLogger->info('Install file has been updated. Check the extensions out in the backend!');
		}
		else {
			// create or update the semantic web (owl) files
			$controller->tryUseCached();
		}
		require_once(JModuleHelper::getLayoutPath('mod_semanticweb'));
	endif;
endif;
// Virtuemart is not enabled, missing or user navigates on any site on the webpage which does not belong to Virtuemart
?>